package rhinestone.Control;

import rhinestone.Model.Staff;
import rhinestone.Model.StaffContainer;

/**
 * This is a controller of staff management.
 *
 * @author Group 2
 * @version 2010.12.22
 */
public class StaffController {
	private StaffContainer staffContainer;

	public StaffController(StaffContainer staffContainer) {
		this.staffContainer = staffContainer;
	}

	public void addStaff(String name, String address, String cpr, String phone, int workingPlace, int rank) {
		Staff staff = new Staff(name, address, cpr, phone, workingPlace, rank);
		staffContainer.addStaff(staff);
	}

	public Staff getStaff(String cpr) {
		return staffContainer.getStaff(cpr);
	}

	public void updateStaff(Staff staff, String name, String address, String cpr, String phone, String workingPlace, String rank) {
		if(!name.equals(""))
			staff.setName(name);
		if(!address.equals(""))
			staff.setAddress(address);
		if(!cpr.equals(""))
			staff.setCpr(cpr);
		if(!phone.equals(""))
			staff.setPhone(phone);
		if(!workingPlace.equals("")) {
			try {
				staff.setWorkingPlace(Integer.parseInt(workingPlace));
			} catch(NumberFormatException ex) {
				System.err.println("Working place not changed, wrong number format: " + workingPlace);
			}
		}
		if(!rank.equals("")) {
			try {
				staff.setRank(Integer.parseInt(rank));
			} catch(NumberFormatException ex) {
				System.err.println("Rank not changed, wrong number format: " + rank);
			}
		}

		staffContainer.addStaff(staff);
		System.out.println(" --- Employee updated ---");
	}

	public Staff removeStaff(String cpr) {
		return staffContainer.removeStaff(cpr);
	}
}
